home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 051-075 / disk_066 / nart / rnd.s < prev    next >
Text File  |  1992-05-06  |  798b  |  45 lines

  1. *\
  2. *  :ts=8 bk=0
  3. * Yet Another random number generator.  By Leo Schwab.
  4. * Based on an idea posted on the USENET (Thanks, Sam Dicker!)
  5. * For the MetaComCo assembler
  6. *
  7. * Calling convention:
  8. *  long rnd (range);
  9. *  long range;
  10. *
  11. * Assembling:
  12. *  df1:c/assem rnd.s -o rnd.o
  13. * 8606.30
  14. */
  15.  
  16.         section code
  17.         xdef    _rnd
  18.  
  19. _rnd        lea    rndseed,a0    Get address of seed
  20.         move.l    4(sp),d1    Get range argument
  21.         tst.l    d1
  22.         ble.s    setseed        Go reset seed
  23.  
  24.  
  25.         move.l    (a0),d0        Get seed
  26.         ADD.L   D0,D0
  27.         BHI.S   over
  28.         EORI.L  #$1D872B41,D0
  29. over
  30.         move.l    d0,(a0)        Save new seed
  31.         andi.l    #$ffff,d0    Coerce into word
  32.         andi.l    #$ffff,d1
  33.         divu    d1,d0        Divide by range
  34.         swap    d0         and get remainder (modulus)
  35.         ext.l    d0
  36.         rts
  37.  
  38. setseed        neg.l    d1        Probably don't need this
  39.         move.l    d1,(a0)
  40.         rts
  41.  
  42.         section data
  43. rndseed        dc.l    0
  44.